package com.nicho.util;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/*
 * @Author: 姜东浩
 * @Date: 2021-11-09 09:10:21
 * @LastEditors: 姜东浩
 * @LastEditTime: 2021-11-11 09:05:04
 * @Description: 关闭文件操作流的工具类
 */
public class CloseStream {

    /**
     * @description:关闭FileOutputStream fos, FileInputStream fis
     * @param fos 字节输出流
     * @param fis 字节输入流
     * @author: 姜东浩
     */
    public static void closeFileStream(FileOutputStream fos, FileInputStream fis) {

        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    /**
     * @description:关闭ObjectInputStream ois, ObjectOutputStream oos
     * @param ois 反序列化流
     * @param oos 序列化流
     * @author: 姜东浩
     */
    public static void closeObjectStream(ObjectInputStream ois, ObjectOutputStream oos) {

        if (ois != null) {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (oos != null) {
            try {
                oos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    /**
     * @description:关闭ObjectInputStream ois
     * @param 反序列化流
     * @author: 姜东浩
     */
    public static void closeObjectInputStream(ObjectInputStream ois) {

        if (ois != null) {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    /**
     * @description:关闭ObjectOutputStream oos
     * @param oos 序列化流s
     * @author: 姜东浩
     */
    public static void closeObjectOutputStream(ObjectOutputStream oos) {

        if (oos != null) {
            try {
                oos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
}